
# Create your views here.
from django.http import HttpResponse
from django.http.response import JsonResponse

# from ftplib import FTP
# from ftplib import FTP_TLS
# import os
# from django.shortcuts import render
# from django.template import loader

from .forms import UploadFileForm
from .somewhere import handle_uploaded_file
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def upload_file(request):
    json = {
        'status':0
    }
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            #print(form)
            handle_uploaded_file( request )
        else:
            json = {
                'status': 1,
                'description':'参数提交不合法'
            }
    else:
        json = {
            'status':1
        }
    response = JsonResponse( json )
    response["Access-Control-Allow-Origin"] = "*"
    response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
    response["Access-Control-Max-Age"] = "1000"
    response["Access-Control-Allow-Headers"] = "*"
    return response